package com.fecean.aabbc.netty.client.prod7;

import com.fecean.aabbc.netty.dispatcher7.ChannelSender;
import com.fecean.aabbc.netty.message7.ResponseMessage;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 ** 客户端发送
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-03-17 16:44
 * @blame Team
 */
@Slf4j
@Component
public class NettyClientSender {


    /**
     ** 请求发送对象
     */
    @Resource
    ChannelSender channelSender;

    /**
     ** 当前客户端通道
     */
    private Channel channel;

    /**
     ** 设置当前客户端通道
     *
     * @param channel 当前客户端通道
     */
    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    /**
     ** 清空当前客户端通道
     */
    public void clear() {
        this.channel = null;
    }

    /**
     ** 发送通知
     *
     * @param tenantId 租户ID
     * @param cinemaCode 影院编码
     * @param content 消息内容
     */
    public void sendNotice(String tenantId, String cinemaCode, String content){
        channelSender.sendNotice(channel, tenantId, cinemaCode, content);
    }

    /**
     ** 发送请求并接收响应结果
     *
     * @param tenantId 租户ID
     * @param cinemaCode 影院编码
     * @param content 消息内容
     */
    public ResponseMessage sendRequest(String tenantId, String cinemaCode, String content){
        return channelSender.sendRequest(channel, tenantId, cinemaCode, content);
    }
}
